<!--
 * @Descripttion: 申请记录
 * @Author: xiao li
 * @Date: 2020-12-03 12:02:09
 * @LastEditors: xiao li
 * @LastEditTime: 2021-01-19 13:33:51
-->
<template>
    <div>
        <top-nav></top-nav>
        <div class="page-main">

        <div class="page-search-form">
          <el-form @submit.native.prevent :inline="true" :model="searchForm" ref="searchForm">
            <el-form-item label="输入查询" prop="name">
              <el-input placeholder="用户昵称" v-model="searchForm.name"></el-input>
            </el-form-item>
            <el-form-item>
              <lb-button size="medium" type="primary"  icon="el-icon-search" style="margin-right:5px" @click="getTableDataList(1)" >{{$t('action.search')}}</lb-button>
              <lb-button size='medium' icon="el-icon-refresh-left" style="margin-right:5px" @click="resetForm('searchForm')" >{{$t('action.reset')}}</lb-button>
            </el-form-item>
          </el-form>
        </div>
          <el-table
              v-loading='loading'
              :data="tableData"
              :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
              style="width: 100%">
                <el-table-column
                  prop="nickName"
                  label="用户昵称">
                </el-table-column>
                <el-table-column
                  prop="avatarUrl"
                  label="用户头像">
                  <template slot-scope="scope">
                    <lb-image :src='scope.row.avatarUrl'></lb-image>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="wx_code"
                  label="提现微信号">
                </el-table-column>
                <el-table-column
                  prop="true_price"
                  label="提现金额">
                </el-table-column>
                <el-table-column
                  prop="status"
                  label="状态">
                  <template slot-scope="scope">
                    <div>{{statusList[scope.row.status]}}</div>
                  </template>
                </el-table-column>
                <el-table-column
                  prop='create_time'
                  label="创建时间"
                 >
                  <template slot-scope="scope">
                      <p>{{scope.row.create_time | handleTime(1)}}</p>
                      <p>{{scope.row.create_time | handleTime(2)}}</p>
                  </template>
                </el-table-column>
                <el-table-column
                    label="操作">
                    <template slot-scope="scope">
                        <div class="table-operate" v-if="scope.row.status === 1">
                            <lb-button size='mini' plain type='primary' @click="toConfirm(scope.row.id,1)">在线转账</lb-button>
                            <lb-button size='mini' plain type='success' @click="toConfirm(scope.row.id,0)">线下转账</lb-button>
                            <lb-button size='mini' plain type='danger' @click="toConfirm(scope.row.id,2)">拒绝提现</lb-button>
                        </div>
                    </template>
                </el-table-column>
          </el-table>
          <lb-page
            :batch='false'
            :page='searchForm.page'
            :pageSize='searchForm.limit'
            :total='total'
            @handleSizeChange='handleSizeChange'
            @handleCurrentChange='handleCurrentChange'
            >
          </lb-page>
        </div>

    </div>
</template>

<script>
export default {
  data () {
    return {
      statusList: {
        '-1': '提现失败',
        1: '申请中',
        2: '已提现'
      },
      loading: false,
      searchForm: {
        page: 1,
        limit: 10,
        name: ''
      },
      tableData: [],
      total: 0,
      showDialog: {
        growth: false,
        stored: false,
        record: false
      },
      dialogForm: {
        key: ''
      }
    }
  },
  activated () {
    this.getTableDataList()
  },
  methods: {
    toResetForm () {
      this.$refs.multipleTable.clearSelection()
    },
    resetForm (name) {
      this.$refs[name].resetFields()
      this.getTableDataList(1)
    },
    getTableDataList (flag) {
      if (flag) this.searchForm.page = 1
      this.loading = true
      let param = this.$util.pick(this.searchForm, [
        'page',
        'limit',
        'name'
      ])
      let {range = ''} = this.searchForm
      if (range) {
        param.start_time = range[0] / 1000
        param.end_time = range[1] / 1000 + 24 * 3600 - 1
      }
      this.$api.memberCashList(param).then(res => {
        this.loading = false
        if (res.code === 200) {
          this.tableData = res.data.data
          this.total = res.data.total
        }
      })
    },
    handleSizeChange (val) {
      this.searchForm.limit = val
      this.handleCurrentChange(1)
    },
    handleCurrentChange (val) {
      this.searchForm.page = val
      this.getTableDataList()
    },
    beforeClose () {
      for (let key in this.showDialog) {
        this.showDialog[key] = false
      }
      this.getTableDataList()
    },
    toShowDialog (item, key) {
      item.key = key
      item.growth_old = item.growth
      item.stored_old = item.stored
      this.dialogForm = item
      this.showDialog[key] = true
    },
    /**
     * @method 在线转账/线下转账/拒绝提现
     */
    toConfirm (id, type) {
      let message = type === 2 ? '请确认是否要拒绝提现？' : this.$t('tips.confirmOperate')
      this.$confirm(message, this.$t('tips.reminder'), {
        confirmButtonText: this.$t('action.comfirm'),
        cancelButtonText: this.$t('action.cancel'),
        type: 'warning'
      }).then(() => {
        let methodModel = type === 2 ? 'memberCashNoPass' : 'memberCashPass'
        let param = type === 2 ? {id} : {id, type}
        this.$api[methodModel](param).then(res => {
          if (res.code === 200) {
            this.$message.success(this.$t('tips.successOper'))
            this.getTableDataList()
          }
        })
      })
    }
  },
  filters: {
    handleTime (val, type) {
      let time = type === 1 ? moment(val * 1000).format('YYYY-MM-DD') : type === 2 ? moment(val * 1000).format('HH:mm:ss') : moment(val * 1000).format('YYYY-MM-DD HH:mm:ss')
      return time
    }
  }
}
</script>

<style lang="scss" scoped>
.el-select,
.el-input{
  width: 200px;
}
</style>
